package fr.afcepf.atod19.groupeJV.data.implementations;

import java.util.List;


import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import fr.afcepf.atod19.groupeJV.data.interfaces.IDataArticle;
import fr.afcepf.atod19.groupeJV.entity.Article;
import fr.afcepf.atod19.groupeJV.entity.Commentaire;
import fr.afcepf.atod19.groupeJV.entity.Jeu;

@Stateless
public class DataArticleImpl implements IDataArticle {
	@PersistenceContext(unitName="ProjetAtod")
	EntityManager em;
	
	public List<Article> getAllArticle() {
		
		Query query = em.createQuery("FROM Article article ");
		@SuppressWarnings("unchecked")
		List<Article> listArticlesQuery = query.setMaxResults(1).getResultList();
		return listArticlesQuery;
	}
	
	public Article getArcticleJeux(Jeu jeu) {
		Query query = em.createQuery(	"FROM				Article a " +
										"WHERE				a.jeu = "+ jeu.getIdJeu());
		
		Article retour = (Article) query.getResultList().get(0);
		return retour;
	}
}
